package com.wolf.controller;

import com.wolf.pojo.Wl_commodity_brand;
import com.wolf.service.Wl_commodity_brandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.wolf.util.execl;
import com.wolf.util.Math;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

@Controller
@ComponentScan
public class Wl_commodity_brandController {

    @Autowired
    Wl_commodity_brandService wl_commodity_brandService;

    /***
     * 查询所有品牌信息
     * @param modelMap
     * @return
     */
    @RequestMapping("wl_commodity_brand_getAll")
    public String getAll(ModelMap modelMap) {
        List<Wl_commodity_brand> wl_commodity_brandList = this.wl_commodity_brandService.getAll();

        modelMap.addAttribute("wl_commodity_brandList", wl_commodity_brandList);

        return "table_wl_commodity_brand";
    }

    /***
     * 多条件模糊查询品牌信息
     * @param chnBrand
     * @param endBrand
     * @param beginCreateTime
     * @param endCreateTime
     * @param status
     * @param modelMap
     * @return
     */
    @RequestMapping("wl_commodity_brand_fuzzyQuery")
    public String fuzzyQuery(@RequestParam("chnBrand")String chnBrand, @RequestParam("engBrand")String endBrand, @RequestParam("beginCreateTime")String beginCreateTime, @RequestParam("endCreateTime")String endCreateTime, @RequestParam("status")String status, ModelMap modelMap) {
        List<Wl_commodity_brand> wl_commodity_brandList = this.wl_commodity_brandService.fuzzyQuery("%"+chnBrand+"%", "%"+endBrand+"%", beginCreateTime, endCreateTime, status);

        modelMap.addAttribute("wl_commodity_brandList", wl_commodity_brandList);

        return "table_wl_commodity_brand";
    }

    /***
     * 新增品牌信息
     * @param wl_commodity_brand
     * @param brandTagId
     * @param request
     * @return
     */
    @RequestMapping("wl_commodity_brand_insertSelective")
    public String insertSelective(Wl_commodity_brand wl_commodity_brand, @RequestParam("brandTagId")String brandTagId, HttpServletRequest request){

        System.out.println(brandTagId);

        wl_commodity_brand.setId(Math.random());

        System.out.println(wl_commodity_brand.getId());

        wl_commodity_brand.setCreatetime(new Date());

        request.getSession().setAttribute("wl_commodity_brand",wl_commodity_brand);
        request.getSession().setAttribute("brandTagId",brandTagId);

        int result=this.wl_commodity_brandService.insertSelective(wl_commodity_brand);

        System.out.println(result);

        return "forward:Wl_commodity_brand_tag_rel_insertTagRelWithBrand";
    }

    /***
     * 查询品牌详情
     * @param id
     * @param modelMap
     * @return
     */
    @RequestMapping("wl_commodity_brand_getById")
    public String getById(String id,ModelMap modelMap){
        Wl_commodity_brand wl_commodity_brand=this.wl_commodity_brandService.selectByPrimaryKey(id);

        modelMap.addAttribute("wl_commodity_brand",wl_commodity_brand);

        return "wl_commodity_brand_update";
    }

    /***
     * 修改品牌信息
     * @param wl_commodity_brand
     * @return
     */
    @RequestMapping("wl_commodity_brand_update")
    public String update(Wl_commodity_brand wl_commodity_brand){

        Date date=new Date();

        wl_commodity_brand.setUpdatetime(date);

        int result=this.wl_commodity_brandService.updateByPrimaryKeySelective(wl_commodity_brand);

        System.out.println(result);

        return "redirect:wl_commodity_brand_getAll";
    }

    /***
     * 根据品牌编号获取其标签信息
     * @param id
     * @param modelMap
     * @return
     */
    @RequestMapping("wl_commodity_brand_getBrandTagById")
    public String getBrandTagById(@RequestParam("id")String id,ModelMap modelMap){
        List<Wl_commodity_brand> wl_commodity_brandList=this.wl_commodity_brandService.getBrandTagById(id);

        modelMap.addAttribute("wl_commodity_brandList",wl_commodity_brandList);

        return "table_wl_commodity_brand_tagDetail";
    }

    /***
     * 禁用品牌
     * @param id
     * @return
     */
    @RequestMapping("wl_commodity_brand_delete")
    public String delete(@RequestParam("id")String id){
        Wl_commodity_brand wl_commodity_brand=this.wl_commodity_brandService.selectByPrimaryKey(id);

        wl_commodity_brand.setStatus(0);

        this.wl_commodity_brandService.updateByPrimaryKey(wl_commodity_brand);

        return "redirect:wl_commodity_brand_getAll";
    }
}
